<template>
  <div class="index">
    <!-- 顶部 -->
    <div class="top"><Admin></Admin></div>
    <!-- bottom -->
    <div class="bottom">
      <div class="left"><SideNav></SideNav></div>
      <div class="right">
        <div class="content">
          <el-scrollbar style="height: 100%;">
            <!-- 当前位置 -->
            <div class="current_position">
              <p class="breadcrumb">当前位置 :</p>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item class="up">生活服务</el-breadcrumb-item>
                <el-breadcrumb-item>技工列表</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <!-- 列表 -->
            <div class="userlist">
              <div class="status_box">
                <div class="input" @keyup.enter="findList()">
                  <el-input v-model="input" placeholder="技工姓名/手机号" clearable></el-input>
                </div>
                <div class="search"><el-button @click="findList()">搜索</el-button></div>
              </div>
              <div class="table">
                <el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
                  <el-table-column type="selection" fixed="left" width="50"></el-table-column>
                  <el-table-column prop="id" label="技工ID"></el-table-column>
                  <el-table-column prop="userName" label="姓名"></el-table-column>
                  <el-table-column prop="phoneNumber" label="手机"></el-table-column>
                  <el-table-column prop="num" label="订单"></el-table-column>
                  <el-table-column prop="userLastLoginTime" label="最近登录时间" :formatter="dateForma"></el-table-column>
                  <el-table-column prop="enable" label="账号状态" align="center">
                    <template slot-scope="scope">
                      <span v-if="scope.row.status== 1" class="userStatus1">接单中</span>
                      <span v-if="scope.row.status== 2" class="userStatus2">休息</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" fixed="right"  width="200">
                    <template slot-scope="scope">
                      <el-button @click="goToDetails(scope.row)" type="text" size="small">查看</el-button>
                      <el-button @click="goTodelete(scope.row)" type="text" size="small">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[10,20,30,40,50]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  let moment = require("moment")
  import Admin from '@/components/Admin.vue'
  import SideNav from '@/components/SideNav.vue'

  export default {
    name: 'ArtisanList',
    components:{
      Admin,
      SideNav
    },
    data () {
      return {
        page: 1,//页码
        pageSize: 50,//每页条数
        total: 0,/* 总的条数 */
        currentPage: 0,/* 前往第几页 */
        input: null,// 搜索输入框
        tableData: [],// 表格
        multipleSelection: [], // 选择后的列表
      }
    },
    mounted() {
      this.findList();
    },
    methods: {
      // 时间格式过滤
      dateForma(row,column){
        var date = row[column.property];
        if(date == undefined){
          return ''
        }
        return moment(date).format("YYYY-MM-DD HH:mm:ss")
      },
      // 获取所有技工列表
      findList(){
        console.log(this.value)
        console.log(this.input)
        this.$axios.post(this.baseURL1+'admin/mechanicUser/list',{
          "key":this.input,//搜索内容
          "page":this.page,
          "size":this.pageSize,
          "requestSource":"PC"
        }).then((res)=>{
          console.log(res,"所有技工");
          if(res.data.code==1){
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      // 表格的全选
      handleSelectionChange(val) {
        console.log(val);
        this.multipleSelection = val;
      },
      // 选择的每页条数
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.findList();
      },
      // 当前页面
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page = val;
        this.findList();
      },
      //查看
      goToDetails(row){
        console.log(row)
        var data = row;
        this.$router.push({
          path: '/ArtisanListDetail',
          query: {
            data: data,
          }
        })
      },
      //删除
      goTodelete(row){
        console.log(row.id)
        var ids = row.id.toString().split("");
        console.log(ids)
        this.$confirm('确认删除该技工?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post(this.baseURL1+'admin/mechanicUser/del',{
            "ids": ids,
            "requestSource":"PC",
          }).then((res)=>{
            if(res.data.code==0){
              this.$message({
                type: 'success',
                message: '删除技工成功'
              });
              setTimeout(()=>{
                this.findList();
              },1000)
            }else{
              this.$message({
                type: 'error',
                message: res.data.msg
              });
            }
          }).catch((err)=>{
            console.log('request fail', err);
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  @import '@/assets/css/index.scss'; //这个分号一定要写，要不会报错
  @import '@/assets/css/user.scss'; //这个分号一定要写，要不会报错
</style>
